package com.dom.domweb.modular.controller;

import com.dom.common.model.vo.apply.*;
import com.dom.domweb.common.RspModel;
import com.dom.domweb.common.TabPager;
import com.dom.domweb.modular.service.PurcCredService;
import com.dom.domweb.utils.TradeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 采购单控制逻辑层
 * @Author xllei
 * @Date 2018/12/9 3:14 AM
 * @Version 1.0
 **/
@RestController
@RequestMapping("/purc/cred")
public class PurcCredController {
    @Autowired
    private PurcCredService purcCredService;

    @RequestMapping("/getPurcCredList")
    public TabPager getPurcCredPager(@RequestParam("limit") int limit, @RequestParam("page") int page, @RequestParam("exchStartDate") String exchStartDate,
                                     @RequestParam("exchEndDate") String exchEndDate, @RequestParam("deliStartDate") String deliStartDate,
                                     @RequestParam("deliEndDate") String deliEndDate, @RequestParam("makerId") Integer marketId, @RequestParam("stat") Integer stat,
                                     @RequestParam("storCode") Integer storCode, @RequestParam("suppCode") Integer suppCode, @RequestParam("verfyStat") Integer verfyStat) {
        P059R request = new P059R();
        TradeUtil.setHead(request);

        request.setPn(page);
        request.setPs(limit);
        request.setExchStartDate(exchStartDate);
        request.setExchEndDate(exchEndDate);
        request.setDeliStartDate(deliStartDate);
        request.setDeliEndDate(deliEndDate);
        request.setMakerId(marketId);
        request.setStorCode(storCode);
        request.setSuppCode(suppCode);
        request.setStat(stat);
        request.setVerfyStat(verfyStat);

        P059A response = purcCredService.findPurcCredList(request);
        return new TabPager(response.getCredData(), response.getTotalNum());
    }

    @RequestMapping(value = "/addPurcCred", method = RequestMethod.POST)
    public RspModel addPurcCred(@RequestBody P050R request){
        TradeUtil.setHead(request);

        P050A response = purcCredService.addPurcCredBill(request);

        return new RspModel(response.getCredId());
    }

    /**
     * 获取采购单明细-不分页
     * @param credId
     * @return
     */
    @RequestMapping(value = "/getPurcCredDetailList", method = RequestMethod.GET)
    public TabPager getPurcCredDetailList( @RequestParam("credId") Integer credId){
        P069R request = new P069R();
        TradeUtil.setHead(request);
        request.setCredId(credId);

        P069A response = purcCredService.findPurcCredDetailList(request);
        return new TabPager(response.getCredDetailData(), response.getTotalNum());
    }

    @RequestMapping(value = "/editPurcCred", method = RequestMethod.POST)
    public RspModel editPurcCred(@RequestBody P052R request){
        TradeUtil.setHead(request);

        P052A response = purcCredService.editPurcCredBill(request);
        return new RspModel(response.getCredId());
    }
}
